package com.dalimao.floateutil.slice;

import com.dalimao.floateutil.*;
import com.dalimao.floateutil.util.LogUtil;
import com.dalimao.floateutil.widget.CanvasView;
import com.dalimao.floateutil.widget.LoadingWidget;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.components.Component;
import ohos.ai.cv.text.Text;

public class MainAbilitySlice extends AbilitySlice {

    CanvasView canvasView;
    LoadingWidget widget;
    Component text_view;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        widget= (LoadingWidget) findComponentById(ResourceTable.Id_loading_view);

        text_view= findComponentById(ResourceTable.Id_text_view);
        text_view.setClickedListener(view->{
            widget.openAnimator();
        });

        canvasView = (CanvasView) findComponentById(ResourceTable.Id_canvas_view);
        canvasView.setMaxNum(100);
        AnimatorValue animatorValue = new AnimatorValue();
        animatorValue.setDuration(3000);
        //循环次数
        animatorValue.setCurveType(Animator.CurveType.DECELERATE);
        animatorValue.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                int value = (int) (v*100);
                canvasView.setcurrendNum(value);
            }
        });


        canvasView.setClickedListener(view->{
            animatorValue.start();
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}